package wps.util {
import flash.display.BitmapData;
import flash.display.DisplayObject;
import flash.utils.ByteArray;

import mx.graphics.codec.PNGEncoder;

import spark.components.Image;

public class ImageDataGenerator {

	private var _displayObject:DisplayObject;

	//--------------------------------------------------------------------------
	//
	// Constructor
	//
	//--------------------------------------------------------------------------

	public function ImageDataGenerator(displayObject:DisplayObject) {
		_displayObject = displayObject;
	}
	
	//--------------------------------------------------------------------------
	//
	// methods
	//
	//--------------------------------------------------------------------------

	/**
	 * 把显示对象转换为PNG图片，并得到图片数据
	 */
	public function getPngData():ByteArray {
		var bmdata:BitmapData = new BitmapData(_displayObject.width, _displayObject.height, true, 0x00000000);
		bmdata.draw(_displayObject);
		
		var pngEncoder:PNGEncoder = new PNGEncoder();
		return pngEncoder.encode(bmdata);
	}
	
}

}
